<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>商店销售系统</title>
<script type="text/javascript"
	src="<%=basePath%>/statics/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		var sort = ${detail.sortId};
		$("#sorts option:eq(" + sort + ")").attr("selected", 'selected');
	});

	function changed() {
		var sort = $("#sorts").val();
		window.location.href = "${pageContext.request.contextPath }/init?sortId="
				+ sort;
	};
</script>
</head>
<body>

	<c:if test="${details==null}">
		<script type="text/javascript">
			window.location.href = "${pageContext.request.contextPath }/init";
		</script>
	</c:if>
	<center style="margin:150px auto;">
		<table border="1">
			<tr>
				请选择商品分类
				<select onchange="changed();" id="sorts">
					<option class="sortName" value="0">请选择</option>
					<c:forEach var="sort" items="${sorts}">
						<option class="sortName" class=sort value="${sort.id}">${sort.name}</option>
					</c:forEach>
				</select>
			</tr>
			<tr>
				<td>商品编号</td>
				<td>商品名称</td>
				<td>商品分类</td>
				<td>产地</td>
				<td>生产日期</td>
				<td>单价(元)</td>
				<td>剩余数量</td>
				<td>购买</td>
			</tr>
			<c:forEach var="detail" varStatus="status" items="${details}">
				<tr <c:if  test="${status.index%2 eq 0}">bgcolor="#B4CDCD"</c:if>>
					<td>${detail.id }</td>
					<td>${detail.name }</td>
					<td>${detail.sortName }</td>
					<td>${detail.address }</td>
					<td>${detail.createDate }</td>
					<td>${detail.price }</td>
					<td>${detail.remaining }</td>
					<td><a
						href="${pageContext.request.contextPath }/shop?id=${detail.id }">购买</a>
					</td>
				</tr>
			</c:forEach>
			<c:if test="${statu==1}">
				<tr align="center">
					<td colspan="8">购买成功</td>
				</tr>
			</c:if>
			<c:if test="${statu==2}">
				<tr align="center">
					<td colspan="8">购买失败</td>
				</tr>
			</c:if>
		</table>
		<div align="center">
			<c:if test="${detail.pageNo>1}">
				<a class="page"
					href="${pageContext.request.contextPath }/init?pageNo=1&sortId=${detail.sortId}">首页</a>
				<a class="page"
					href="${pageContext.request.contextPath }/init?pageNo=${detail.pageNo-1}&sortId=${detail.sortId}">上一页</a>
			</c:if>
			<c:if test="${detail.pageNo<detail.totalPageCount}">
				<a class="page"
					href="${pageContext.request.contextPath }/init?pageNo=${detail.pageNo+1}&sortId=${detail.sortId}">下一页</a>
				<a class="page"
					href="${pageContext.request.contextPath }/init?pageNo=${detail.totalPageCount}&sortId=${detail.sortId}">末页</a>
			</c:if>
			第${detail.pageNo}页/共${detail.totalPageCount}页
		</div>
	</center>
</body>
</html>
